from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

# Create your models here.

class Team(models.Model):
    name=models.CharField(max_length=64)
    numer=models.IntegerField()
    
    class Meta:
        verbose_name_plural = "Podgrupy"
        verbose_name="Podgrupa"
    
    def __str__(self):
        return "Grupa %s" % self.name
    
class Profil(models.Model):
    user=models.ForeignKey(User, unique=True)
    team=models.ForeignKey(Team, null=True, blank=True)
    nauczyciel=models.BooleanField()
    indeks=models.IntegerField(unique=True, null=True, blank=True)
    
    class Meta:
        verbose_name_plural = "Profile"

    def isNauczyciel(self):
        if self.nauczyciel==True: 
            return True
        else:
            return False

        
    def __str__(self):
        return "Profil uzytkownika %s" % self.user
    
def createUserProfile(sender, instance, created, **kwargs):
    if created:
        profile, created = Profil.objects.get_or_create(user=instance)
        
post_save.connect(createUserProfile, sender=User)
        

    
    